<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算属性</title>
</head>
<body>
<div id="app">
    <p>原始字符串: {{ message }}</p>
    <p>计算后反转字符串: {{ reversedMessage }}</p>
</div>
====================================================
<div id="appTwo">
    <p>{{ site }}</p>
</div>
</body>
<script src="../static/js/vue.js"></script>
<script>
    var vm = new Vue({
        el:'#app',
        data:{
            message: 'Runoob!'
        },
        computed:{
            reversedMessage:function () {
                // `this` 指向 vm 实例
                return this.message.split('').reverse().join('')
            }
        }
    })

    var vm = new Vue({
        el: '#appTwo',
        data: {
            name: 'Google',
            url: 'http://www.google.com'
        },
        computed: {
            site: {
                // getter
                get: function () {
                    return this.name + ' ' + this.url
                },
                // setter
                set: function (newValue) {
                    var names = newValue.split(' ')
                    this.name = names[0]
                    this.url = names[names.length - 1]
                }
            }
        }
    })
    // 调用 setter， vm.name 和 vm.url 也会被对应更新
    vm.site = '菜鸟教程 http://www.runoob.com';
    document.write('name: ' + vm.name);
    document.write('<br>');
    document.write('url: ' + vm.url);
</script>
</html>